//
//  Eidt_InformationViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/6.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Eidt_InformationViewController.h"

#import "VPImageCropperViewController.h"
#define ORIGINAL_MAX_WIDTH 640.0f

#import "Edit_PassWordViewController.h"
#import "Select_DirectlyleaderViewController.h"
#import "Binding_MobilePhoneViewController.h"
#import "Edit_TelephonyViewController.h"

@interface Eidt_InformationViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UITextViewDelegate, UIActionSheetDelegate, VPImageCropperDelegate ,UINavigationControllerDelegate ,UIImagePickerControllerDelegate>

@property (nonatomic, strong) UITableView * tableView;
//
@property (nonatomic, strong) UIImageView * image_Pic;
@property (nonatomic, strong) UILabel * edit_sex;
@property (nonatomic, strong) UITextField * edit_JobTitle;
@property (nonatomic, strong) UILabel * edit_Tel;
@property (nonatomic, strong) UILabel * edit_Telnumber;
@property (nonatomic, strong) UITextField * edit_Weixin;
@property (nonatomic, strong) UITextField * edit_Mail;
@property (nonatomic, strong) UITextField * edit_QQ;
@property (nonatomic, strong) UITextView * edit_WorkIntroduct;
@property (nonatomic, strong) UILabel * WorkIntroduct_PlaceHold;
//
@property (nonatomic, assign) CGFloat keyboard_Height;


@end

@implementation Eidt_InformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"编辑资料";
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 70, 15)];
    lbl_return.text = @"个人资料";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 90, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //右保存
    UIButton * btn_eidt = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_eidt.frame = CGRectMake(SCREEN_WIDTH - 5 - 50, 20 + 7, 50, 30);
    [btn_eidt setTitle:@"保存" forState:(UIControlStateNormal)];
    [btn_eidt setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_eidt.titleLabel.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:btn_eidt];
    [btn_eidt addTarget:self action:@selector(btn_eidtAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右保存
- (void )btn_eidtAction:(UIButton *)sender
{
    NSLog(@"点击保存数据,调接口");
}

//tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 14)
    {
        return 120;
    }
    else
    {
        return 65;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    
    if(indexPath.row == 0)
    {//头像
        UILabel * lbl_heads = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_heads.text = @"头像";
        lbl_heads.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_heads.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_heads];
        
        UILabel * eidt_Heads = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_heads.frame) + 10, 100, 15)];
        eidt_Heads.text = @"修改头像";
        eidt_Heads.textColor = [UIColor blackColor];
        eidt_Heads.font = [UIFont systemFontOfSize:17];
        [cell addSubview:eidt_Heads];
    
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
        
        self.image_Pic = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 50, 7.5, 50, 50)];
        self.image_Pic.image = [UIImage imageNamed:@"heads.jpg"];
        self.image_Pic.layer.cornerRadius = 25;
        self.image_Pic.layer.masksToBounds = YES;
        [cell addSubview:self.image_Pic];
    }
    else if(indexPath.row == 1)
    {//昵称
        UILabel * lbl_Nickname = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Nickname.text = @"昵称";
        lbl_Nickname.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Nickname.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Nickname];
        
        UILabel * eidt_Nickname = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Nickname.frame) + 10, SCREEN_WIDTH - 30, 15)];
        eidt_Nickname.text = @"员工姓名(不可自己修改)";
        eidt_Nickname.textColor = [UIColor grayColor];
        eidt_Nickname.font = [UIFont systemFontOfSize:17];
        [cell addSubview:eidt_Nickname];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 2)
    {//账号
        UILabel * lbl_account = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_account.text = @"账号";
        lbl_account.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_account.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_account];
        
        UILabel * eidt_account = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_account.frame) + 10, SCREEN_WIDTH - 30, 15)];
        eidt_account.text = @"1866999XXXX";
        eidt_account.textColor = [UIColor grayColor];
        eidt_account.font = [UIFont systemFontOfSize:17];
        [cell addSubview:eidt_account];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 3)
    {//密码
        UILabel * lbl_password = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_password.text = @"密码";
        lbl_password.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_password.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_password];
        
        UILabel * eidt_password = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_password.frame) + 10, SCREEN_WIDTH - 30, 15)];
        eidt_password.text = @"立即修改";
        eidt_password.textColor = [UIColor blackColor];
        eidt_password.font = [UIFont systemFontOfSize:17];
        [cell addSubview:eidt_password];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 4)
    {//性别
        UILabel * lbl_sex = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_sex.text = @"性别";
        lbl_sex.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_sex.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_sex];
        
        self.edit_sex = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_sex.frame) + 10, SCREEN_WIDTH - 30, 15)];
        self.edit_sex.text = @"男";
        self.edit_sex.textColor = [UIColor blackColor];
        self.edit_sex.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.edit_sex];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 5)
    {//公司
        UILabel * lbl_company = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_company.text = @"公司";
        lbl_company.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_company.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_company];
        
        UILabel * edit_company = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_company.frame) + 10, SCREEN_WIDTH - 30, 15)];
        edit_company.text = @"山东XX网络科技有限公司";
        edit_company.textColor = [UIColor grayColor];
        edit_company.font = [UIFont systemFontOfSize:17];
        [cell addSubview:edit_company];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 6)
    {//部门
        UILabel * lbl_department = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_department.text = @"部门";
        lbl_department.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_department.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_department];
        
        UIImageView * image_L = [[UIImageView alloc] initWithFrame:CGRectMake(27, CGRectGetMaxY(lbl_department.frame) + 10, 10, 10)];
        image_L.image = [UIImage imageNamed:@"L-style.png"];
        [cell addSubview:image_L];
        
        UILabel * edit_department = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_L.frame) + 10, CGRectGetMaxY(lbl_department.frame) + 10, SCREEN_WIDTH - CGRectGetMaxX(image_L.frame) - 20, 15)];
        edit_department.text = @"销售XX部";
        edit_department.textColor = [UIColor grayColor];
        edit_department.font = [UIFont systemFontOfSize:17];
        [cell addSubview:edit_department];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 7)
    {//职位
        UILabel * lbl_JobTitle = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_JobTitle.text = @"职位";
        lbl_JobTitle.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_JobTitle.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_JobTitle];
        
        self.edit_JobTitle = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_JobTitle.frame) + 6.5, SCREEN_WIDTH - 30, 22)];
        self.edit_JobTitle.delegate = self;
        self.edit_JobTitle.returnKeyType = UIReturnKeyDone;
        self.edit_JobTitle.text = @"销售经理";
        self.edit_JobTitle.textColor = [UIColor blackColor];
        self.edit_JobTitle.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.edit_JobTitle];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 8)
    {//直属上级
        UILabel * lbl_Leader = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Leader.text = @"直属上级";
        lbl_Leader.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Leader.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Leader];
        
        UILabel * eidt_Leader = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Leader.frame) + 10, SCREEN_WIDTH - 30, 15)];
        eidt_Leader.text = @"销售总监-XXX";
        eidt_Leader.textColor = [UIColor blackColor];
        eidt_Leader.font = [UIFont systemFontOfSize:17];
        [cell addSubview:eidt_Leader];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 9)
    {//手机
        UILabel * lbl_Tel = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Tel.text = @"手机";
        lbl_Tel.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Tel.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Tel];
        
        self.edit_Tel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Tel.frame) + 10, SCREEN_WIDTH - 30, 15)];
        self.edit_Tel.text = @"1866999XXXX";
        self.edit_Tel.textColor = [UIColor blackColor];
        self.edit_Tel.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.edit_Tel];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
        
        //长按出现复制
        UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressCellHandle:)];
        longPressGesture.minimumPressDuration = 0.9;
        [cell addGestureRecognizer:longPressGesture];
    }
    else if(indexPath.row == 10)
    {//电话
        UILabel * lbl_Telnumber = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Telnumber.text = @"电话";
        lbl_Telnumber.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Telnumber.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Telnumber];
        
        self.edit_Telnumber = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Telnumber.frame) + 10, SCREEN_WIDTH - 30, 15)];
        self.edit_Telnumber.text = @"未填写";
        self.edit_Telnumber.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.edit_Telnumber];
        
        if([self.edit_Telnumber.text isEqualToString:@"未填写"])
        {
            self.edit_Telnumber.textColor = [UIColor grayColor];
        }
        else
        {
            self.edit_Telnumber.textColor = [UIColor blackColor];
        }
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 11)
    {//微信
        UILabel * lbl_Weixin = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Weixin.text = @"微信";
        lbl_Weixin.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Weixin.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Weixin];
        
        self.edit_Weixin = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Weixin.frame) + 6.5, SCREEN_WIDTH - 30, 22)];
        self.edit_Weixin.delegate = self;
        self.edit_Weixin.font = [UIFont systemFontOfSize:17];
        self.edit_Weixin.placeholder = @"未填写";
        self.edit_Weixin.returnKeyType = UIReturnKeyDone;
        [cell addSubview:self.edit_Weixin];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 12)
    {//邮箱
        UILabel * lbl_Mail = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_Mail.text = @"邮箱";
        lbl_Mail.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_Mail.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_Mail];
        
        self.edit_Mail = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_Mail.frame) + 6.5, SCREEN_WIDTH - 30, 22)];
        self.edit_Mail.delegate = self;
        self.edit_Mail.font = [UIFont systemFontOfSize:17];
        self.edit_Mail.placeholder = @"未填写";
        self.edit_Mail.returnKeyType = UIReturnKeyDone;
        [cell addSubview:self.edit_Mail];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 13)
    {//QQ
        UILabel * lbl_QQ = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_QQ.text = @"QQ";
        lbl_QQ.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_QQ.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_QQ];
        
        self.edit_QQ = [[UITextField alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_QQ.frame) + 6.5, SCREEN_WIDTH - 30, 22)];
        self.edit_QQ.delegate = self;
        self.edit_QQ.font = [UIFont systemFontOfSize:17];
        self.edit_QQ.placeholder = @"未填写";
        self.edit_QQ.returnKeyType = UIReturnKeyDone;
        [cell addSubview:self.edit_QQ];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 64, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 14)
    {//工作介绍
        UILabel * lbl_WorkIntroduce = [[UILabel alloc] initWithFrame:CGRectMake(15, 12.5, 100, 15)];
        lbl_WorkIntroduce.text = @"工作介绍";
        lbl_WorkIntroduce.textColor = [UIColor colorWithRed:46/255.0 green:115/255.0 blue:210/255.0 alpha:1.0];
        lbl_WorkIntroduce.font = [UIFont systemFontOfSize:15];
        [cell addSubview:lbl_WorkIntroduce];
        
        self.edit_WorkIntroduct = [[UITextView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(lbl_WorkIntroduce.frame) + 5, SCREEN_WIDTH - 20, 80)];
        self.edit_WorkIntroduct.delegate = self;
        self.edit_WorkIntroduct.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.edit_WorkIntroduct];
        
        self.WorkIntroduct_PlaceHold = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(lbl_WorkIntroduce.frame) + 15, 100, 15)];
        self.WorkIntroduct_PlaceHold.text = @"未填写";
        self.WorkIntroduct_PlaceHold.textColor = [UIColor lightGrayColor];
        self.WorkIntroduct_PlaceHold.font = [UIFont systemFontOfSize:17];
        [cell addSubview:self.WorkIntroduct_PlaceHold];
        
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 119, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
    }
    
    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row)
    {
        case 0:
        {
//            NSLog(@"点击抽屉效果,选择项有三个");
            UIActionSheet * choiceSheet = [[UIActionSheet alloc] initWithTitle:@"请选择获取方式" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"本地相册", @"照相机", nil];
            [choiceSheet showInView:self.view];
        }
            break;
        case 3:
        {
//            NSLog(@"点击进入修改密码页面");
            Edit_PassWordViewController * edit_PassWordViewController = [[Edit_PassWordViewController alloc] init];
            [self showViewController:edit_PassWordViewController sender:nil];
        }
            break;
        case 4:
        {
//            NSLog(@"点击弹出时间选择器,选择男女");
            UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
            
            [self presentViewController:alert animated:YES completion:^{
            }];
            
            UIAlertAction * action_Man = [UIAlertAction actionWithTitle:@"男" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                self.edit_sex.text = @"男";
            }];
            
            UIAlertAction * action_Woman = [UIAlertAction actionWithTitle:@"女" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                self.edit_sex.text = @"女";
            }];
            
            UIAlertAction * action_Cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
            }];
            
            [alert addAction:action_Man];
            [alert addAction:action_Woman];
            [alert addAction:action_Cancel];
        }
            break;
        case 8:
        {
//            NSLog(@"点击后,跳转到公司结构表");
            Select_DirectlyleaderViewController * select_DirectlyleaderViewController = [[Select_DirectlyleaderViewController alloc] init];
            [self presentViewController:select_DirectlyleaderViewController animated:YES completion:^{
            }];
        }
            break;
        case 9:
        {
//            NSLog(@"点击后,跳转到绑定手机号界面");
            Binding_MobilePhoneViewController * binding_MobilePhoneViewController = [[Binding_MobilePhoneViewController alloc] init];
            [self showViewController:binding_MobilePhoneViewController sender:nil];
        }
            break;
        case 10:
        {
//            NSLog(@"点击后,跳转到保存电话号码");
            Edit_TelephonyViewController * edit_TelephonyViewController = [[Edit_TelephonyViewController alloc] init];
            [self showViewController:edit_TelephonyViewController sender:nil];
        }
            break;
        default:
            break;
    }
}

#pragma mark - textView代理
- (void)textViewDidChange:(UITextView *)textView
{
    if([textView.text length] == 0)
    {
        self.WorkIntroduct_PlaceHold.hidden = NO;
    }
    else
    {
        self.WorkIntroduct_PlaceHold.hidden = YES;
    }
}

#pragma mark - textfield代理
- (void)textFieldDidEndEditing:(UITextField *)textField
{//保存数据
    
}

#pragma mark - scrollView代理
- (void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.edit_JobTitle resignFirstResponder];
    [self.edit_Weixin resignFirstResponder];
    [self.edit_Mail resignFirstResponder];
    [self.edit_QQ resignFirstResponder];
    [self.edit_WorkIntroduct resignFirstResponder];
}

#pragma mark - 键盘高度
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    self.keyboard_Height = keyboardRect.size.height;
//    NSLog(@"键盘高度是  %lf",self.keyboard_Height);
    
    if([self.edit_JobTitle isFirstResponder])
    {
        if(self.tableView.contentOffset.y < 520 - (SCREEN_HEIGHT - 64 - self.keyboard_Height))
        {
            [UIView animateWithDuration:0.7f animations:^{
                
                self.tableView.contentOffset = CGPointMake(0, 520 - (SCREEN_HEIGHT - 64 - self.keyboard_Height));
            }];
        }
    }
    else if([self.edit_Weixin isFirstResponder])
    {
        if(self.tableView.contentOffset.y < 12 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height))
        {
            [UIView animateWithDuration:0.7f animations:^{
                
                self.tableView.contentOffset = CGPointMake(0, 12 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height));
            }];
        }
    }
    else if([self.edit_Mail isFirstResponder])
    {
        if(self.tableView.contentOffset.y < 13 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height))
        {
            [UIView animateWithDuration:0.7f animations:^{
                
                self.tableView.contentOffset = CGPointMake(0, 13 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height));
            }];
        }
    }
    else if([self.edit_QQ isFirstResponder])
    {
        if(self.tableView.contentOffset.y < 14 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height))
        {
            [UIView animateWithDuration:0.7f animations:^{
                
                self.tableView.contentOffset = CGPointMake(0, 14 * 65 - (SCREEN_HEIGHT - 64 - self.keyboard_Height));
            }];
        }
    }
    else if([self.edit_WorkIntroduct isFirstResponder])
    {
        if(self.tableView.contentOffset.y < 14 * 65 + 120 - (SCREEN_HEIGHT - 64 - self.keyboard_Height))
        {
            [UIView animateWithDuration:0.7f animations:^{
                
                self.tableView.contentOffset = CGPointMake(0, 14 * 65 + 120 - (SCREEN_HEIGHT - 64 - self.keyboard_Height));
            }];
        }
    }
}

#pragma mark - 长按及出现复制按钮
-(void)longPressCellHandle:(UILongPressGestureRecognizer *)gesture
{
    [self becomeFirstResponder];
    
    UIMenuController * menuController = [UIMenuController sharedMenuController];
    UIMenuItem *copyItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(menuCopyBtnPressed:)];
    menuController.menuItems = @[copyItem];
    [menuController setTargetRect:gesture.view.frame inView:gesture.view.superview];
    [menuController setMenuVisible:YES animated:YES];
    
    [UIMenuController sharedMenuController].menuItems = nil;
}

-(void)menuCopyBtnPressed:(UIMenuItem *)menuItem
{
    [UIPasteboard generalPasteboard].string = self.edit_Tel.text;
}

-(BOOL)canBecomeFirstResponder
{
    return YES;
}
















//****************************处理图片********************************
#pragma mark VPImageCropperDelegate
- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage
{
    [cropperViewController dismissViewControllerAnimated:YES completion:^{
        // TO DO
        [self saveImage:editedImage withName:@"avatar.jpg"];
        //加数据(接口需要的)
        //        NSData *imageData = UIImagePNGRepresentation(editedImage);
        
        self.image_Pic.image = editedImage;
    }];
}

#pragma mark - 保存图片至沙盒
- (void )saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController
{
    [cropperViewController dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {// 拍照
        if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos])
        {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
            if ([self isFrontCameraAvailable]) {
                controller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            }
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                             }];
        }
    }
    else if (buttonIndex == 0)
    {// 从相册中选取
        if ([self isPhotoLibraryAvailable])
        {
            UIImagePickerController *controller = [[UIImagePickerController alloc] init];
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
            [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
            controller.mediaTypes = mediaTypes;
            controller.delegate = self;
            
            [self presentViewController:controller
                               animated:YES
                             completion:^(void){
                             }];
        }
    }
}

#pragma mark - UIImagePickerControllerDelegate
//触发事件
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^() {
        UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        portraitImg = [self imageByScalingToMaxSize:portraitImg];
        // 裁剪
        VPImageCropperViewController *imgEditorVC = [[VPImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(1, 100.0f, SCREEN_WIDTH - 2, SCREEN_WIDTH) limitScaleRatio:3.0];
        imgEditorVC.delegate = self;
        imgEditorVC.view.backgroundColor = [UIColor blackColor];
        [self presentViewController:imgEditorVC animated:YES completion:^{
            // TO DO
        }];
    }];
}

//取消事件
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^(){
        
    }];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
}

#pragma mark camera utility
- (BOOL) isCameraAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable
{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable
{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}

- (BOOL) doesCameraSupportTakingPhotos
{
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) canUserPickVideosFromPhotoLibrary
{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) canUserPickPhotosFromPhotoLibrary
{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType
{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0)
    {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType])
        {
            result = YES;
            *stop= YES;
        }
    }];
    
    return result;
}

#pragma mark image scale utility
- (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage
{
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height)
    {
        btHeight = ORIGINAL_MAX_WIDTH;
        btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else
    {
        btWidth = ORIGINAL_MAX_WIDTH;
        btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
}

- (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize
{
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil) NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    
    return newImage;
}


@end
